package com.atyixiang.cmn.config;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
import org.springframework.format.support.FormattingConversionServiceFactoryBean;

import java.time.format.DateTimeFormatter;
import java.util.Collections;

@Configuration
public class PageConfig {

    /*分页*/
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }

    /*字符串转为Date类型*/
    @Bean
    public ConversionService conversionService(){
        FormattingConversionServiceFactoryBean factoryBean=new FormattingConversionServiceFactoryBean();
        DateTimeFormatterRegistrar registrar=new DateTimeFormatterRegistrar();
        registrar.setDateFormatter(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        factoryBean.setFormatterRegistrars(Collections.singleton(registrar));
        factoryBean.afterPropertiesSet();
        return factoryBean.getObject();
    }

}
